Developer Documentation
PATH  WebObjects 4.5 Documentation > Getting Started With Direct to Java Client

   

Using the Rule Editor

Suppose you want to right align all text fields that contain numeric data. The Assistant isn't sophisticated enough to allow you to do this. However, you can configure your application to have this alignment behavior by writing a custom rule. The procedure is as follows:

  1. Start the Rule Editor.

    On Mac OS X Server, choose WebObjects Rule Editor in the Apple menu.

    On Windows, choose Rule Editor in the WebObjects program group.

    When the Rule Editor starts, it opens a new, untitled rule file.

  2. Click New to create a new rule.

  3. Set the rule's condition, key, and value.

    Note that the Rule Editor uses formal rule terminology to refer to parts of a rule. Formally, a rule is expressed as follows:

    (condition) => key = value

    The condition of a rule is known as the left hand side of the rule (lhs), the key is known as the right hand side key (rhs key), and the value is known as the right hand side value (rhs value). For example, a rule that right aligns numeric text fields can be expressed as follows:

    (not (attribute = nil)) and ((attribute.valueClassName = 'NSNumber') or (attribute.valueClassName = 'NSDecimalNumber')) => alignment = "Right"

    In this rule, the condition or lhs is:

    ((not (attribute = nil)) and ((attribute.valueClassName = 'NSNumber') or (attribute.valueClassName = 'NSDecimalNumber')))

    The key or rhs key is "alignment", and the value or rhs value is "Right."

  4. Set the rule's priority to 50.

    The priority of the Assistant's rules is 100. Use a lower priority than 100 if you want the Assistant's rules to be preferred to your own rules, or a higher priority otherwise. Don't create rules that have the same priority as the Assistant's rules, because this can confuse the Assistant.

    The priority of the default rules is 0, so both the Assistant's and your custom rules are preferred to the default rules.

  5. Set the rule's assignment class to Assignment.

    In the Class pop-up list on the right side of the window, select Assignment. This class is selected by default, so you shouldn't actually have to change it. Other assignment classes allow you to programmatically determine rule results. For more information, see Developing WebObjects Applications with Direct to Web.

  6. Name the rule file d2w.d2wmodel and save it in the Resources folder of your application's project.

    Rules are stored in files with the extension .d2wmodel.

    In addition to your custom rule file, there are two other rule files that are used by an application: a file containing the default rules and a file containing the Assistant's rules. The default rules are also in a file named d2w.d2wmodel, but the default rule file is located in the Resources folder of the DirectToJavaClient framework. The other rule file is the Assistant's rule file. It is located in the Resources folder of an application's project along with the custom rules file, but it has the name user.d2wmodel.

    You can look at the Assistant rules by opening the user.d2wmodel; simply double-click the file, which opens it in the Rule Editor. However, don't edit the Assistant's file because the Assistant writes out the file whenever it saves, removing rules it doesn't create itself. By storing your custom rules in the d2w.d2wmodel file, you can write custom rules and still use the Assistant.


© 1999 Apple Computer, Inc. – (Draft. Last updated 05 Jan 00)